<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="edu.njust.LabSystem.entity.*,edu.njust.LabSystem.Service.*" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'StudentHomePage.jsp' starting page</title>
    <%@ include file="/public/include.jsp" %>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript">
        function itemClick1() {
            $('#item1').attr('class', 'selected-item');
            $('#item2').attr('class', 'unselected-item');
        }

        function itemClick2() {
            $('#item2').attr('class', 'selected-item');
            $('#item1').attr('class', 'unselected-item');
        }

        function itemClick3() {
            $('#item3').attr('class', 'selected-item');
            $('#item4').attr('class', 'unselected-item');
            $('#kexuan').css("display", '');
            $('#yixuan').css("display", 'none');

        }

        function itemClick4() {
            $('#item4').attr('class', 'selected-item');
            $('#item3').attr('class', 'unselected-item');
            $('#kexuan').css("display", 'none');
            $('#yixuan').css("display", '');
        }
    </script>
</head>
<body>

<%
    String uid = (String) session.getAttribute("uid");
    IStudentService service = new IStudentService();
    Student student = service.getStudentById(uid);
%>
<div class="nav nav-tabs success" style="background-color: #c9c6fa;height:60px;">
    <div class="" style="float: left;margin-left: 30px">
        <img class="user-photo" style="" src="img/face.jpg"/>
    </div>
    <div class="nav-item" style="float:left;margin-left:5px;">
        <a style=""><%=student.getName() %>
        </a>
    </div>
    <div class="nav-item">
        <a href="#">学生主页</a>
    </div>
    <div class="nav-item" style="margin-right:5px;">
        <img class="icon" style="width: 20px;height: 20px;" src="img/home.png"/>
    </div>

    <div class="nav-item" style="">
        <a style="" href="StudentInfo.jsp?action=StudentInfoController&uid=${uid}">个人中心</a>
    </div>
    <div class="nav-item" style="margin-right:5px;">
        <img class="icon" style="clear:both;width: 20px;height: 20px;" src="img/person_white.png"/>
    </div>
</div>

<%--    表1：学生课表--%>
<div class="table-container">
    <div class="table-top">
        <span class="table-title">学生课表</span>
    </div>
    <div class="table-main">
        <div class="main_left">
            <ul id="nav1" class="">
                <li id="item1" onclick="itemClick1()" class="unselected-item"><a>实验课程</a></li>
                <li id="item2" onclick="itemClick2()" class="selected-item"><a>开放性实验</a></li>
            </ul>
        </div>
        <div class="main_right">
            <table id="shiyanke" class="table table-bordered class-table">
                <tr class="head_tr">
                    <td></td>
                    <td>
                        <p>周一</p>
                        <p>11/15</p>
                    </td>
                    <td>
                        <p>周二</p>
                        <p>11/16</p>
                    </td>
                    <td>
                        <p>周三</p>
                        <p>11/17</p>
                    </td>
                    <td>
                        <p>周四</p>
                        <p>11/18</p>
                    </td>
                    <td>
                        <p>周五</p>
                        <p>11/19</p>
                    </td>
                    <td>
                        <p>周六</p>
                        <p>11/20</p>
                    </td>
                    <td>
                        <p>周日</p>
                        <p>11/21</p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p>08:00</p>
                        <p>10:25</p>
                    </td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td><p>10:40</p>
                        <p>12:15</p></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="selected-item"><%
                        String cid = student.getClassid();
                        ExperimentService experimentService = new ExperimentService();
                        List<Experiment> experiments = experimentService.getExperimentByClassid(cid);
                        LabAppointmentService labAppointmentService = new LabAppointmentService();

                        if (experiments == null || experiments.size() < 1) {
                            //out.print("<script language='javascript'>alert('没有数据');</script>");
                        } else {
                            for (Experiment experiment : experiments) {
                                String eid = experiment.getId();
                                LabAppointment labAppoint = labAppointmentService.getLabAppointmentByExperiment(eid);
                                if (experiment.isOpen() == false) {
                                    String labId = labAppoint.getLab();
                                    LabService labService = new LabService();
                                    Lab lab = labService.getByLabId(labId);
                                    //String lid=experiment.getLab();lid.getName();
                    %>
                        <%=experiment.getName()%>
                        <%=experiment.getTeacher()%><br>
                        <%=lab.getName()%>

                        <%=labAppoint.getAppoint_date()%><br>
                        第<%=labAppoint.getAppoint_time()%>大节
                        <%
                                    }
                                }
                            }
                        %></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td><p>14:00</p>
                        <p>15:35</p></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td><p>15:50</p>
                        <p>18:15</p></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
                <tr>
                    <td><p>19:00</p>
                        <p>21:25</p></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>
        </div>
    </div>
</div>

<%--    表2：预约选课--%>
<div class="table-container" style="margin-top: 70px;margin-bottom: 70px">
    <div class="table-top">
        <span class="table-title">预约选课</span>
    </div>
    <div class="table-main">
        <div class="main_left">
            <ul class="">
                <li id="item3" onclick="itemClick3()" class="selected-item"><a>可选实验</a></li>
                <li id="item4" onclick="itemClick4()" class=""><a href="javascript:yixuanSelect()">已选实验</a></li>
            </ul>
        </div>
        <div class="main_right">
            <%--            已选实验--%>
            <table id="yixuan" class="table class-table">
                <%
                    StudentAppointmentService sAservice = new StudentAppointmentService();
                    List<StudentAppointment> studentAppointments = sAservice.getStudentAppointmentByStudent(uid);
                    if (studentAppointments == null || studentAppointments.size() < 1) {
                        //out.print("<script language='javascript'>alert('没有数据');</script>");
                    } else {
                        for (StudentAppointment studentAppointment : studentAppointments) {
                            String exid = studentAppointment.getExperiment();
                            ExperimentService exService = new ExperimentService();
                            Experiment ex = exService.getExperimentById(exid);
                            String labId = studentAppointment.getLab();
                            LabService labService = new LabService();
                            Lab lab = labService.getByLabId(labId);
                %>
                <tr class="">
                    <td><%=ex.getName()%>
                    </td>
                    <td><%=ex.getTeacher()%>
                    </td>
                    <td><%=lab.getName()%>
                    </td>
                    <td><%=studentAppointment.getAppoint_date()%>
                    </td>
                    <% session.setAttribute("exid", exid);%>
                    <td>
                        <button class="btn btn-default"><a href="SdelAppointmentController?exid=<%=ex.getId() %>"
                                                           onclick="return confirm('是否确定取消预约？')">取消预约</a></button>
                    </td>
                </tr>

                <%
                        }
                    }
                %>
            </table>
            <%--            可选实验--%>
            <table id="kexuan" class="table class-table">
                <%
                    List<Experiment> openExperiments = experimentService.getExperiments();
                    if (openExperiments == null || openExperiments.size() < 1) {
                        //out.print("<script language='javascript'>alert('没有数据');</script>");

                    } else {
                        for (Experiment openExperiment : openExperiments) {
                            boolean flag = false;
                            if (openExperiment.isOpen() == true) {
                                String eid = openExperiment.getId();
                                session.setAttribute("eid", eid);
                                LabAppointment labAppoint = labAppointmentService.getLabAppointmentByExperiment(eid);
                                String labId = labAppoint.getLab();
                                LabService labService = new LabService();
                                Lab lab = labService.getByLabId(labId);
                                //System.out.println("jsp:"+eid);
                                //System.out.println("shiyan:"+openExperiment.getName());
                                for (StudentAppointment studentAppointment : studentAppointments) {
                                    String str = studentAppointment.getExperiment();
                                    if (eid.equals(str)) {
                                        flag = true;
                                        //System.out.println("非预约:"+eid);
                                        //openExperiments.remove(openExperiment);
                                        break;
                                    }
                                }
                                if (flag == false) {

                %>
                <%--        <c:set var="eid" value="<% openExperiment.getId(); %>"/>--%>
                <% request.setAttribute("eid", openExperiment.getId()); %>
                <tr>
                    <td><%=openExperiment.getName()%>
                    </td>
                    <td><%=openExperiment.getTeacher()%>
                    </td>
                    <td><%=lab.getName()%>
                    </td>
                    <td><%=labAppoint.getAppoint_date()%>
                    </td>
                    <td>第<%=labAppoint.getAppoint_time()%>大节</td>
                    <td>
                        <button class="btn btn-danger xuanke-btn"><a
                                href="SelectLab.jsp?action=SelectLabController&eid=${eid}">选课</a></button>
                    </td>
                </tr>
                <%
                                }
                            }
                        }
                    }
                    //System.out.println("jsp:"+session.getAttribute("eid"));
                %>
            </table>
        </div>
    </div>
</div>
</body>
</html>
